import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:life_milestones/MS-Model/MS-milestone.dart';
import 'package:life_milestones/controller/MS-global-user-controller.dart';
import 'package:life_milestones/controller/MS-mile-stone-controller.dart';
import 'package:stroke_text/stroke_text.dart';
import 'package:provider/provider.dart';
class MSPostTextPage extends StatefulWidget{
  final int month;
  const MSPostTextPage({super.key, required this.month});

  @override
  State<StatefulWidget> createState() {
    return _MSPostTextPageState();
  }

}

class _MSPostTextPageState extends State<MSPostTextPage>{
  TextEditingController textEditingController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Consumer<MSMileStoneController>(builder: (BuildContext context,MSMileStoneController controller,Widget? child){
      return Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: const Color(0xFF148857),
        body:SizedBox.expand(
            child: Stack(children: [
              Positioned(left: 0,right: 0,top: ScreenUtil().statusBarHeight,bottom: 0,child: Image.asset("images/mile-stone-post-bg.png",fit: BoxFit.fitWidth,),),
              Positioned(left: 0,right: 0,top: ScreenUtil().statusBarHeight,bottom: 0,
                  child:Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(padding: EdgeInsets.only(top: 32.w,left: 24.w),child: InkWell(
                        onTap: (){
                          Navigator.of(context).pop();
                        },
                        child: Image.asset("images/back.png",width: 25.w,fit: BoxFit.fitWidth,),
                      ),),
                      Padding(padding: EdgeInsets.only(top: 12.w),
                        child: SizedBox(width: double.infinity, child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            StrokeText(text:"Things I want to record",strokeWidth: 2.w,strokeColor: Color(0xFF065F39),
                              textStyle: TextStyle(
                                  fontSize: 25.sp,
                                  fontWeight: FontWeight.bold,
                                  color: Colors.white
                              ),
                            )
                          ],
                        ),),
                      ),
                      Padding(padding: EdgeInsets.only(left: 24.w,right: 24.w,top: 73.w),
                        child: Container(
                          width: 327.w,
                          height: 451.w,
                          decoration: const BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage("images/post-bg.png")
                              )
                          ),
                          padding: EdgeInsets.only(left: 44.w,right: 40.w,top: 97.w,bottom: 107.w),
                          child: Column(
                            children: [
                              Expanded(child: TextField(
                                controller: textEditingController,
                                textInputAction: TextInputAction.done,
                                decoration:  InputDecoration(
                                  border: InputBorder.none,
                                  hintText:"The most meaningful growth story",
                                  hintStyle: TextStyle(
                                    fontSize: 18.sp,
                                    fontWeight: FontWeight.w500,
                                  ),
                                ),
                                maxLines: 5,
                                style: TextStyle(
                                    fontSize: 18.sp,
                                    fontWeight: FontWeight.bold,
                                    color: const Color(0xFF065F39)
                                ),
                                onChanged: (String value){},
                              )),
                              Divider(height: 19.w,color: Colors.transparent,),
                              InkWell(
                                onTap: (){
                                  if(textEditingController.text.isNotEmpty){
                                     controller.addMileStone(MSMileStone(userId: MSGlobalUserController().user!.userId!,type: Type.text,month: widget.month,content: textEditingController.text));
                                     Navigator.of(context).pop();
                                  }
                                },
                                child: Container(
                                  width: 165.w,
                                  height: 39.w,
                                  decoration: const BoxDecoration(
                                      image: DecorationImage(
                                          image: AssetImage("images/home-save-button-bg.png"),
                                          fit: BoxFit.fill
                                      )
                                  ),
                                  alignment: Alignment.center,
                                  child: StrokeText(text:"publish",strokeColor: Colors.white,strokeWidth: 1.w,textStyle:TextStyle(

                                      fontSize: 12.sp,
                                      fontWeight: FontWeight.bold,
                                      color: Color(0xFF333333)
                                  ),),
                                ),)
                            ],
                          ),
                        ),
                      )
                    ],
                  ))
            ],)
        ),
      );
    });
  }

}